package com.daydayup.learn;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * 使用SynchronousQueue的线程池
 */
public class SynchronousQueuePool {
    public static void main(String[] args) throws InterruptedException {

//        Executors.newFixedThreadPool(10);
//        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS,
//                new SynchronousQueue<>(true), new DefaultThreadFactory("sync"), new ThreadPoolExecutor.CallerRunsPolicy());
//
//        threadPool.execute(() -> {
//            System.out.println("AAA->"+System.currentTimeMillis());
//            try {
//                Thread.sleep(3000);
//                System.out.println("AAAAAAAAAAA->"+System.currentTimeMillis());
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//        });
//
//        threadPool.execute(() -> {
//            System.out.println("BBB->"+System.currentTimeMillis());
//            try {
//                Thread.sleep(3000);
//                System.out.println("BBBBBBBBBBBBBB->"+System.currentTimeMillis());
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//        });
//
//        threadPool.execute(() -> {
//            System.out.println("CCC->"+System.currentTimeMillis());
//            try {
//                Thread.sleep(3000);
//                System.out.println("CCCCCCCCCCCCCCCCCCC->"+System.currentTimeMillis());
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//        });
        ArrayBlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(2);
        blockingQueue.put("A");
        blockingQueue.put("B");
        blockingQueue.take();
        blockingQueue.take();
        blockingQueue.take();

        // AtomicStampedReference<String> stampedReference = new AtomicStampedReference<String>();
    }
}
